package com.rxtxdemo.rxtxdemo.applicationevent.listener;

import com.rxtxdemo.rxtxdemo.applicationevent.even.ComRegisterEvent;
import com.rxtxdemo.rxtxdemo.demo.MyLister;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

//执行指令策略2
@Service
@Slf4j
public class J2Service {
    @EventListener
    @Async
    public void onApplicationEvent(ComRegisterEvent arg0) throws InterruptedException {
        MyLister.sum++;
        //System.out.println("开始延迟j222222222:"+Thread.currentThread().getId());
        Thread.sleep(1000);

        // System.out.println("异步执行j22222221:"+ Thread.currentThread().getId());
//        Map m=(Map)arg0.getSource();
//        int two=Integer.parseInt(m.get("two").toString());
//        if(two>12){
//            log.info("J1设备开启修改J3设备参数！！！！");
//            Thread.sleep(5000);
//        }else{
//            log.info("J2设备开启状态&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
//        }
//        m.put("two", String.valueOf(RandomUtil.randomInt(1,30)));
//        m.put("three",String.valueOf(RandomUtil.randomInt(1,30)));
//        System.out.println("同步执行QQ！！！");
//        System.out.println("线程id：j22222222222222" + Thread.currentThread().getId());
//        System.out.println("线程名称：" + Thread.currentThread().getName());


        System.out.println("J2服务接到通知，给 " + arg0.getSource());
    }

}
